What are the various ways to send data from a controller to view?
1192
31-May-2017
Manish Kumar
31-May-2017ViewBag: It is a dynamic property.
Controller:: ViewBag.Name = “Mindstick”;
View:: @ViewBag.Name
ViewData: It is a Dictionary object derived from the ViewDataDictionary class. It requires type casting and null check for complex data types.
Controller:: ViewData[“Name”] = “Mindstick”;
View:: @ViewData[“Name”]
ViewBag and ViewData spans for a server call.
TempData: It is a dictionary derived from the TempDataDictionary class. It stores data in a short live session and spans for a HTTP request. It is used when moving from a controller to another or from an action method to another. It is for the current and subsequent request only. It requires type casting and null check for complex data types.